package com.example.administrator.about_huanxin;

import android.app.Application;
import android.util.Log;

import com.hyphenate.EMContactListener;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMOptions;

import cn.bmob.v3.Bmob;

/**
 * Created by Administrator on 2017/3/8.
 */
public class AboutHiApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        initEm();
        initBmob();
        setListener();
    }

    private void initBmob() {
        Bmob.initialize(this, "517c5eb87fffe15df92289e4bcff9b68");
    }

    private void initEm() {
        EMOptions options = new EMOptions();
// 默认添加好友时，是不需要验证的，改成需要验证,false:需要手动同意;true:后台自动添加
//        options.setAcceptInvitationAlways(false);
        options.setAcceptInvitationAlways(true);
//初始化
        EMClient.getInstance().init(this, options);
//在做打包混淆时，关闭debug模式，避免消耗不必要的资源
        EMClient.getInstance().setDebugMode(true);
    }

    //设置监听
    private void setListener() {
        setContactListener();
    }

    //设置联系人监听
    private void setContactListener() {
        EMClient.getInstance().contactManager().setContactListener(new EMContactListener() {
            @Override
            public void onContactAdded(String s) {
                //好友请求被同意
            }

            @Override
            public void onContactDeleted(String s) {
                //好友请求被拒绝
            }

            @Override
            public void onContactInvited(String s, String s1) {
                //收到好友邀请
                Log.e("application","接收到申请...."+s+"...."+s1);
            }

            @Override
            public void onFriendRequestAccepted(String s) {
                //被删除时回调此方法
            }

            @Override
            public void onFriendRequestDeclined(String s) {
                //增加了联系人时回调此方法
            }
        });
    }

}
